package eu.vranckaert.workRegistrationWidget.util;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

/**
 * @author Dirk Vranckaert
 *         Date: 10-jun-2010
 *         Time: 15:18:42
 */
public class Preferences {
	private static final String LOG_TAG = Preferences.class.getName();
	public static final String PREF_NAME = "wrwfacblue";

    public static final String KEY_GPS_USAGE_ALLOWED = "gps_usage_allowed";
    public static final boolean KEY_DEFAULT_GPS_USAGE_ALLOWED = true;
    public static final String KEY_LAST_KNOWN_LOCATION_ALLOWED = "last_known_location_allowed";
    public static final boolean KEY_DEFAULT_LAST_KNOWN_LOCATION_ALLOWED = false;
    public static final String KEY_GPS_LOOKUP_TIMEOUT = "gps_lookup_timeout";
    public static final String KEY_DEFAULT_GPS_LOOKUP_TIMEOUT = "1";
    public static final String KEY_FILE_EXPORT_NAME = "export_default_name";
    public static final String KEY_DEFAULT_FILE_EXPORT_NAME = "registrations-export";
    public static final String KEY_FILE_EXPORT_CSV_SEPARATOR = "export_separator";
    public static final String KEY_DEFAULT_FILE_EXPORT_CSV_SEPARATOR = ";";

    private static final SharedPreferences getSharedPreferences(Context context) {
        return context.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE);
    }

    public static final boolean getGpsUsageAllowed(Context context) {
        Log.d(LOG_TAG, "Looking for the gps usage allowed preference");
        return getSharedPreferences(context).getBoolean(KEY_GPS_USAGE_ALLOWED, KEY_DEFAULT_GPS_USAGE_ALLOWED);
    }

    public static final boolean getLastKnownLocationAllowed(Context context) {
        Log.d(LOG_TAG, "Looking for the last known location allowed preference");
        return getSharedPreferences(context).getBoolean(KEY_LAST_KNOWN_LOCATION_ALLOWED, KEY_DEFAULT_LAST_KNOWN_LOCATION_ALLOWED);
    }

    public static final int getGpsLookupTimeout(Context context) {
        Log.d(LOG_TAG, "Looking for the gps lookup timeout preference");
        String result =  getSharedPreferences(context).getString(KEY_GPS_LOOKUP_TIMEOUT, KEY_DEFAULT_GPS_LOOKUP_TIMEOUT);
        return new Integer(result);
    }

    public static final String getExportFileName(Context context) {
        Log.d(LOG_TAG, "Looking for the file export name");
        return getSharedPreferences(context).getString(KEY_FILE_EXPORT_NAME, KEY_DEFAULT_FILE_EXPORT_NAME);
    }

    public static final String getExportFileCSVSeparator(Context context) {
        Log.d(LOG_TAG, "Looking for the file export seperator");
        String separator = getSharedPreferences(context).getString(KEY_FILE_EXPORT_CSV_SEPARATOR, KEY_DEFAULT_FILE_EXPORT_CSV_SEPARATOR);
        if (separator.length() > 1) {
            separator = KEY_DEFAULT_FILE_EXPORT_CSV_SEPARATOR;
        }
        return separator;
    }
}
